package timing.ukulele.project.intercept;

import timing.ukulele.project.exception.BaseException;
import timing.ukulele.common.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(value = BaseException.class)
    public ResponseResult<String> baseExceptionHandler(Exception e) {
        log.error(e.getMessage(), e.getCause() == null ? e : e.getCause());
        return ResponseResult.error(e.getMessage());
    }

    @ExceptionHandler(value = Exception.class)
    public ResponseResult<String> otherExceptionHandler(Exception e) {
        log.error(e.getMessage(), e);
        return ResponseResult.error("操作失败！");
    }


}
